package com.ruoyi.trans.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    // 定义队列名称
    public static final String QUEUE_NAME = "myQueue";

    // 定义交换机名称
    public static final String EXCHANGE_NAME = "myExchange";

    // 定义路由键
    public static final String ROUTING_KEY = "myRoutingKey";

    // 创建队列
    @Bean
    public Queue queue() {
        return new Queue(QUEUE_NAME, true); // durable: 是否持久化
    }

    // 创建交换机
    @Bean
    public Exchange exchange() {
        return ExchangeBuilder.directExchange(EXCHANGE_NAME)
                .durable(true)  // durable: 是否持久化
                .build();
    }

    // 创建绑定
    @Bean
    public Binding binding(Queue queue, Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(ROUTING_KEY).noargs();
    }
}
